package com.kennedy.atoupdate.web.controller;

import com.kennedy.atoupdate.beans.VersionGroup;
import com.kennedy.atoupdate.beans.common.ResultMsg;
import com.kennedy.atoupdate.service.VersionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by tao.zeng on 2017/8/18.
 */
@Controller
@RequestMapping("/versionGroup")
public class VersionGroupController {
    @Autowired
    private VersionGroupService versionGroupService;

    @PostMapping("/save/{versionInfoId}")
    @ResponseBody
    public ResultMsg delete(@RequestBody List<VersionGroup> versionGroups, @PathVariable("versionInfoId") Long versionInfoId) {
        versionGroupService.deleteByVersionId(versionInfoId);
        try {
            versionGroupService.batchAdd(versionGroups);
        } catch (Exception e) {
            return ResultMsg.error();
        }
        return ResultMsg.success();
    }

    @GetMapping("/get/{versionInfoId}")
    @ResponseBody
    public List<VersionGroup> get(@PathVariable("versionInfoId") Long versionInfoId) {
        return versionGroupService.getListByVersionInfoId(versionInfoId);
    }
}
